package com.wk.wanjetpack.net

import com.wk.base.BASE_URL
import com.wk.wanjetpack.bean.Article
import com.wk.wanjetpack.bean.Chapters
import com.wk.wanjetpack.bean.ResponseListInfo
import com.wk.wanjetpack.bean.WkResponse
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
import retrofit2.http.Path

/**
 * @author peng
 * @date 2021/1/20
 * 说明
 */
interface IApi {

    @GET("/wxarticle/chapters/json")
    suspend fun getList():WkResponse<List<Chapters>>

    @GET("/article/list/{pageIndex}/json")
    suspend fun getArticles(@Path("pageIndex") pageIndex:Int):WkResponse<ResponseListInfo<Article>>


    companion object {

        fun create(): IApi {
            val logger = HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.BASIC }

            val client = OkHttpClient.Builder()
                .addInterceptor(logger)
                .build()

            return Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(IApi::class.java)
        }
    }

}